package com.student.student.repository;

import com.student.common.entity.Student;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

/**
 * 学生数据访问接口
 * 
 * @author student
 * @date 2025
 */
@Repository
public interface StudentRepository extends JpaRepository<Student, String> {
    
    /**
     * 根据条件查询学生
     */
    @Query("SELECT s FROM Student s WHERE " +
           "(:studentId IS NULL OR s.studentId LIKE %:studentId%) AND " +
           "(:name IS NULL OR s.name LIKE %:name%) AND " +
           "(:major IS NULL OR s.major LIKE %:major%) AND " +
           "(:className IS NULL OR s.className LIKE %:className%) AND " +
           "(:status IS NULL OR s.status = :status)")
    Page<Student> findByConditions(@Param("studentId") String studentId,
                                  @Param("name") String name, 
                                  @Param("major") String major, 
                                  @Param("className") String className,
                                  @Param("status") String status,
                                  Pageable pageable);
}
